<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-22 13:13:43
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-26 16:11:12
 * @FilePath: \app-formwork\src\pages\login\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
view.discover
  view.px-32.py-24
    u-swiper(:list="bannerList", indicator, keyName="image", height="200", indicatorMode="line")
  view.card.flex.flex-wrap.px-32.py-20
    view.item.relative.mr-26.mb-28(v-for="(item, index) in moduleList", :key="index", @click="onModule(item.path)")
      image.absolute(:src="item.image")
      text.absolute.f-32.white.px-16.py-28 {{ item.name }}
</template>

<script setup>
import DiscoverBanner from "@/static/images/discover-banner.png";
import DiscoverCard from "@/static/images/discover-card.png";
import { homeApi } from "../../api/home";
import { foundApi } from "@/api/found";
//获取轮播图
// onLoad(() => {
//   getDiscoverInfo();
//   getdiscoverlist();
// });
onShow(()=>{
    getDiscoverInfo();
    getdiscoverlist();
})
//banner
const getDiscoverInfo = () => {
  homeApi.homebanner({ type: 2 }).then((res) => {
    bannerList.value = res.data;
    console.log("1", bannerList.value);
  });
};

//列表
const getdiscoverlist = () => {
  foundApi.discoverlist().then((res) => {
    console.log("ressdsdf", res.data.anpe);
    moduleList.value.forEach((element, index) => {
      if (element.id == 1) {
        element.image = res.data.mydev;
      }
      if (element.id == 2) {
        element.image = res.data.shop;
      }
      if (element.id == 3) {
        element.image = res.data.anpe;
      }
      if (element.id == 4) {
        element.image = res.data.checklog;
      }
    });
  });
};

//操作说明

const bannerList = ref([]);

const moduleList = ref([
  {
    id: 1,
    name: "我的设备",
    image: DiscoverCard,
    path: ""
  },
  {
    id: 2,
    name: "商城",
    image: DiscoverCard,
    path: ""
  },
  {
    id: 3,
    name: "Antiraedi Pedia",
    image: DiscoverCard,
    path: "/pagesA/discover/operate-explain"
  },
  {
    id: 4,
    name: "检测日志",
    image: DiscoverCard,
    path: "/pagesA/discover/detection-log"
  }
]);

// 模块功能跳转
const onModule = (path) => {
  if (!path) {
    uni.showToast({
      title: "功能正在开发中",
      icon: "none",
      mask: true
    });
    return;
  }
  uni.navigateTo({ url: path });
};
</script>

<style lang="stylus" scoped>
.discover {
  .card {
    .item {
      width: 330rpx;
      height: 160rpx;
      
    }

    .item:nth-child(2n) {
      margin-right: 0;
    }

    image {
      width: 330rpx;
      height: 160rpx;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
    }
  }
}
</style>
